package cn.sytton.taffe.web.flw.controller;

import cn.sytton.taffe.excel.annotation.ExportExcel;
import cn.sytton.taffe.framework.base.entity.PageParam;
import cn.sytton.taffe.web.flw.entity.FormDefStructureEntity;
import cn.sytton.taffe.web.flw.service.IFormDefStructureService;
import com.github.pagehelper.PageInfo;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import cn.sytton.taffe.framework.base.controller.BaseController;

/**
 * <p>
 * 工作流表单_结构表 前端控制器
 * </p>
 *
 * @author rock
 * @since 2023-09-27
 */
@Tag(name = "工作流表单_结构表")
@RestController
@RequiredArgsConstructor
@RequestMapping("/flw/form-def-structure")
public class FormDefStructureController extends BaseController {

    private final IFormDefStructureService formDefStructureService;

    @ApiOperationSupport(order = 1)
    @Operation(summary = "查询分页列表")
    @Parameter(name = "pp", description = "分页参数对象", in = ParameterIn.QUERY, required = true)
    @ExportExcel
    @GetMapping
    public PageInfo<FormDefStructureEntity> findListPageOfXml(PageParam pp) {
        return formDefStructureService.findListPageOfXml(pp);
    }

    @ApiOperationSupport(order = 2)
    @Operation(summary = "查询单个对象")
    @Parameter(name = "id", description = "主键ID", in = ParameterIn.PATH, required = true)
    @GetMapping("/{id}")
    public FormDefStructureEntity findById(@PathVariable String id) {
        return formDefStructureService.findById(id);
    }

    @ApiOperationSupport(order = 3)
    @Operation(summary = "创建")
    @PostMapping
    public FormDefStructureEntity create(@RequestBody @Validated FormDefStructureEntity entity) {
        return formDefStructureService.createAndActive(entity);
    }

    @ApiOperationSupport(order = 4)
    @Operation(summary = "更新")
    @PostMapping("/update")
    public FormDefStructureEntity update(@RequestBody @Validated FormDefStructureEntity entity) {
        return formDefStructureService.updateAndActive(entity);
    }

    @ApiOperationSupport(order = 5)
    @Operation(summary = "删除", description = "body: 主键ID数组")
    @PostMapping("/delete")
    public void delete(@RequestBody String[] ids) {
        formDefStructureService.delete(ids);
    }

    @ApiOperationSupport(order = 6)
    @Operation(summary = "激活表单结构")
    @PostMapping("/active/{formId}/{structureId}")
    public FormDefStructureEntity active(@PathVariable String formId, @PathVariable String structureId) {
        return formDefStructureService.active(formId, structureId);
    }

    @ApiOperationSupport(order = 2)
    @Operation(summary = "查询单个对象")
    @Parameter(name = "formId", description = "表单ID", in = ParameterIn.PATH, required = true)
    @GetMapping("/form/{formId}")
    public FormDefStructureEntity findByFormId(@PathVariable String formId) {
        return formDefStructureService.findByFormId(formId);
    }

}
